package com.rc.saas.tenant.service.invoice;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.mapper.invoice.InvoiceOrderMapper;
import com.rc.saas.tenant.model.order.OrderInfo;
import com.rc.saas.tenant.service.order.OrderInfoService;
import com.rc.saas.tenant.vo.order.OrderResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.List;

/**
 * Created by Sven on 2021/06/23
 */
@Service
public class InvoiceOrderServiceImpl implements InvoiceOrderService {
    @Autowired
    private InvoiceOrderMapper invoiceOrderMapper;

    @Autowired
    private OrderInfoService orderInfoService;

    @Override
    public InvoiceOrderMapper getMapper() {
        return invoiceOrderMapper;
    }

    @Override
    public List<Long> listApplyByOrder(String orderNum) {
        OrderInfo orderInfo = orderInfoService.selectOrderByOrderNum(orderNum);
        if (orderInfo == null) {
            return null;
        }
        List<Long> list = invoiceOrderMapper.listApplyByOrder(orderInfo.getOrderId());
        return list;
    }

    @Override
    public PageInfo listOrderByInvoiceApply(Long invoiceApplyId) {
        List<Long> ids = invoiceOrderMapper.listOrderByInvoiceApply(invoiceApplyId);
        if (CollectionUtils.isEmpty(ids)) {
            return null;
        }
        PageHelper.startPage(1,20);
        List<OrderResult> list = orderInfoService.listOrderInIds(ids);
        return new PageInfo(list);
    }
}
